<?php
	require_once("../conexion/conexion.php");
	function ObtenerCod()
	{
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql = "select max(ProCod) from producto";
		$resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
		$cod = mysql_fetch_array($resultado);
		$con->cerrarBD();
		//echo $nom[0];
		return $cod[0];
	}
	$codigo = ObtenerCod();
	$codigo +=1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="../Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />
<link href="../Estilos/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

<script src="../include_js/jquery.js" type="text/javascript"></script>
<script src="../include_js/popcalendar.js" type="text/javascript"></script>
<script type="text/javascript" src="../include_js/jquery.autocomplete.js"></script>

<style>
.texto
{
	font-size:14px;
	margin-left:10px;
	font:Verdana, Arial, Helvetica, sans-serif; 
	color:#0066CC;
}
.borde
{
	/*border:0px solid #6593C0;*/
	border:1px solid #D3E4E5;
}
.asterisco
{
	color:#0000FF;
	font-weight:bold;
}
.radioBorde
{ 
 background:#D3E4E5;
 border:0px solid #89C0C7;
}
.filaPar
{
	background:#81D371; 
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
.filaImpar
{
	background:#AEF1A1;
	font-family:Verdana, Arial, Helvetica, sans-serif; 
    font-size:11px;
	text-align:center;
	vertical-align:middle;
	padding:3px;
}
</style>
<script>
function LimpiarCombo(combo)
{
	while(combo.length > 1)
	{
		combo.remove(combo.length-1);
	}
}

function LlenarCombo(json, combo, nombre)
{
	combo.options[0] = new Option(nombre, '0');
	for(var i=0;i<json.length;i++)
	{
		combo.options[combo.length] = new Option(json[i].data, json[i].id);
	} 
}

function SeleccionandoCombo(combo1, combo2, url, nombre)
{
	combo2 = document.getElementById(combo2);
	if(combo1.options[combo1.selectedIndex].value != "0")
	{
		LimpiarCombo(combo2);
		$.ajax({
			type: 'post',
			dataType: 'json',
			url: url,
			data: {valor: combo1.options[combo1.selectedIndex].value},
			success: function(json){
				LlenarCombo(json,combo2,nombre);
				combo2.disabled = false;
			}
		});
	}
	else
	{
		LimpiarCombo(combo2);
		combo2.disabled = true;
	}
}

function BorraDatos()
{
	num = parseInt(document.getElementById('txtNum').value);
    if(num==1)
	{
		document.getElementById("txtNombre").value= "";
		document.getElementById("txtNombre").focus();
		document.getElementById('txtFecha').value = "";
		document.getElementById('cmb_Proveedor').value = 0;
		document.getElementById("txtObs").value = "";
		document.getElementById("txtCantidad").value = "";
		document.getElementById("txtUnitario").value = "";
		document.getElementById('txtTotal').value= "";
	}
}
</script>
</head>

<body>
<form name="form_compras" id="form_compras" method="post">
<div class='option2'><label style="font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;">Ingreso de Productos a Bodega.</label></div>
<div class='groupbox'>
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="uno">
<tr>
  <td colspan="4" class="borde"><div style="height:5px;"></div></td>
</tr>
<tr>
	<td colspan="3" class="borde"><label class="texto" style="font-weight:bold;">Datos Producto.</label></td>
	<td class="borde"><div style="float:right; clear:none; margin-right:10px;"><label style="color:#0000FF; font-size:12px; font-weight:bold;">Datos Obligatorios(*)</label></div></td>
</tr>
<tr>
  <td colspan="4" class="borde">&nbsp;</td>
</tr>

<tr>
  <td width="17%" class="borde" style="text-align:right"><label class="texto">C&oacute;digo:</label></td>
  <td width="30%" class="borde"><input type="text" name="txtCodigo" id="txtCodigo" size="10" readonly="true" style="background:#E1E1E1" value="<?php echo $codigo;?>"/></td>
  <td width="14%" class="borde" style="text-align:right"><label class="texto">Cantidad:</label></td>
  <td width="39%" class="borde"><input type="text" name="txtCantidad" id="txtCantidad" onkeypress="return validar(event)" />&nbsp;<label class="asterisco">*</label></td>
</tr>
<tr>
  <td class="borde" style="text-align:right"><label class="texto">Nombre:</label></td>
  <td class="borde"><input type="text" name="txtNombre" id="txtNombre" size="30" />&nbsp;<label class="asterisco">*</label></td>
  <td class="borde" style="text-align:right"><label class="texto">V. Unitario:</label></td>
  <td class="borde"><input type="text" name="txtUnitario" id="txtUnitario" onkeyup="puntitos(this,this.value.charAt(this.value.length-1))" />&nbsp;<label class="asterisco">*</label></td>
</tr>
<tr>
  <td class="borde" style="text-align:right"><label class="texto">Fecha Ingreso:</label></td>
  <td class="borde"><input name="txtFecha" type="text" id="txtFecha" size="10">&nbsp;<img src="../imagen/img.gif" width="20" height="14" title="calendario" style="cursor: pointer; border: 1px solid green;" onmouseover="this.style.background='black';" onmouseout="this.style.background=''" onclick="popUpCalendar(txtFecha, form_compras.txtFecha, 'dd-mm-yyyy');" />&nbsp;<label class="asterisco">*</label></td>
  <td class="borde" style="text-align:right"><label class="texto">V. Total:</label></td>
  <td class="borde"><input type="text" name="txtTotal" id="txtTotal" onkeyup="puntitos(this,this.value.charAt(this.value.length-1))" />&nbsp;<label class="asterisco">*</label></td>
</tr>
<tr>
  <td class="borde" style="text-align:right"><label class="texto">Proveedor:</label></td>
  <td class="borde" colspan="3"><select name="cmb_Proveedor" id="cmb_Proveedor">
         <option value="0">--SELECCIONE--</option>
		  <?php
            	$con = new Conexion();
        		$con2 = $con->conexionBD("fpproduccion");
                $sql = "select ProvRut,ProvNombre from proveedor order by ProvNombre";
                $resultado = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
				//$fila = mysql_num_rows($resultado);
				while ($row = mysql_fetch_row($resultado))
				{
					echo "<option value='".$row[0]."'>".$row[1]."</option>";
				}
                $con->cerrarBD();
		?>
      </select>&nbsp;<label class="asterisco">*</label></td>
</tr>
<tr>
  <td class="borde" style="text-align:right"><label class="texto">Observaci&oacute;n:</label></td>
  <td class="borde" colspan="3"><textarea name="txtObs" id="txtObs" cols="58" rows="3"></textarea></td>
</tr>
<tr>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
  <td class="borde">&nbsp;</td>
  <td class="borde"><input type="hidden" name="txtNum" id="txtNum" /></td>
</tr>


<tr>
  <td class="borde" colspan="4"><div class="formtail"><input name="btn_Guardar" id="btn_Guardar" type="button" value=" " class="guardar" /></div></td>
</tr>
</table>
</div>
<div id="mensaje"></div>
</form>
</body>
<script>
$('#btn_Guardar').click(function() 
{ 
        $.ajax({
            type: 'POST',
            url: 'Ingresos/Ingreso_Producto.php',
            data: $('#form_compras').serialize(),
            success: function(data) {
                $('#mensaje').html(data);
				BorraDatos();
            }
        })
});
</script>
</html>
